<%-- 
    Document   : edit_pekerjaan
    Created on : Jul 23, 2012, 2:41:49 PM
    Author     : MiChi
--%>

<%@page import="entity.Pekerjaan"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="dao.PekerjaanDAOImpl"%>
<%@page import="additional.Help"%>
<%@page import="javax.persistence.EntityManager"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<jsp:include page="check_session.jsp" />
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Edit Pekerjaan</title>

        <link href="../style/style.css" rel="stylesheet" type="text/css" />
        <script src="../javascript/calendar_date_input.js"></script>
        <script src="../javascript/validasi_data.js"></script>
        <script type="text/javascript">
            <%
                String nama = "";
                String tglMulai = "";
                String tglSelesai = "";
                long id = Long.MIN_VALUE;
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

                if (request.getParameter("id") == null) {
                    out.write("alert('ID Pekerjaan Kosong!'); \n");
                    out.write("location.href='view_pekerjaan.jsp'; \n");
                } else {
                    try {
                        id = Long.parseLong(request.getParameter("id"));
                        Pekerjaan p = new PekerjaanDAOImpl(Help.getEM()).get(id);

                        if (p != null) {
                            nama = p.getNama();
                            tglMulai = sdf.format(p.getTglMulai());
                            tglSelesai = sdf.format(p.getTglSelesai());
                        } else {
                            out.write("alert('ID Pekerjaan Tidak Ditemukan!'); \n");
                            out.write("location.href='view_pekerjaan.jsp'; \n");
                        }
                    } catch (Exception e) {
                        out.write("alert('Terjadi Kesalahan Saat Mengambil Data'); \n");
                        out.write("location.href='view_pekerjaan.jsp'; \n");
                    }
                }
            %>
    
                function cekData(form) {
                    pesan = "PERINGATAN";
                    hasil = true;
                
                    if(!cekText(form.txtNama)){
                        pesan += "\nNama Pekerjaan Kosong";
                        hasil = false;
                    }
                
                    if(!cekDuaTanggal(form.tglMulai, form.tglSelesai)) {
                        pesan += "\nTanggal Selesai Harus Lebih Dulu dari Tanggal Mulai";
                        hasil = false;
                    }
            
                    if(!hasil) {
                        alert(pesan);
                    }
            
                    return hasil;
                }
            
                function resetData(){
                    document.location.reload(true);
                }
        </script>
    </head>
    <body>
        <div id="central">
            <div id="menuatas">
                <marquee>
                    <h3> Welcome </h3>
                </marquee>
            </div>
            
            <div id="header">
                <% 
                    if(request.getSession().getAttribute("user") == null) {
                        out.write("<a href='/TR_Persistance_Alokasi_Karyawan/Logout'>LogOut</a>");
                    } else {
                        out.write("<a href='/TR_Persistance_Alokasi_Karyawan/login.jsp'>LogIn</a>");
                    }
                %> 
            </div>

            <ul id="navlist">
                <li><a id="n1" href="Home.jsp"><span>Home</span></a></li>
                <li><a id="n2" href="view_karyawan.jsp"><span>Karyawan</span></a></li>
                <li><a id="n3" href="view_pekerjaan.jsp"><span>Pekerjaan</span></a></li>
                <li><a id="n4" href="view_alokasi.jsp"><span>Alokasi Pekerjaan</span></a></li>                               
                <li><a id="n5" href="about.jsp"><span>About</span></a></li>                               
            </ul>

            <div id="content">                
                <div id="rightside">
                    <h1>Edit Data Pekerjaan</h1>
                    <hr><br>

                    <form method="post" action="/TR_Persistance_Alokasi_Karyawan/EditPekerjaan?id=<%=id%>" onsubmit="return cekData(this)">
                        <table>
                            <tr>
                                <td>Nama Pekerjaan</td>
                                <td>:</td>
                                <td><input type="text" name="txtNama" id="txtNama" value="<%=nama%>" /></td>
                            </tr>

                            <tr>
                                <td>Tanggal Mulai</td>
                                <td>:</td>
                                <td>
                                    <script>DateInput('tglMulai', true, 'YYYY-MM-DD','<%=tglMulai%>')</script>
                                </td>
                            </tr>

                            <tr>
                                <td>Tanggal Selesai</td>
                                <td>:</td>
                                <td>
                                    <script>DateInput('tglSelesai', true, 'YYYY-MM-DD', '<%=tglSelesai%>')</script>
                                </td>
                            </tr>

                            <tr>
                                <td colspan="3" align="right">
                                    <input type="submit" value="Edit">
                                    &nbsp;
                                    &nbsp;
                                    <input type="button" value="Reset" onclick="resetData();" />
                                </td>
                            </tr>
                        </table>
                    </form>
                </div>
                <div id="footer">
                    <p>&COPY; copyright TR PERSISTENCE</p>
                </div>
            </div>
    </body>
</html>